

** RISK PREFERENCES **

 	// RISK MONEY GAMES

		* 2 Different versions: version 1 for p1_e5m p3_b p1_b p2_b p1_e12m p1_e13m and version 2 for p1_e7m p2_e2w2w
			* Baseline
			sum g10c_b g10d_b g10e_b g10f_b if p3==1
			sum g10c_b g10d_b g10e_b g10f_b if surveyed_p1_r1_b==1
			sum g10c_b g10d_b g10e_b g10f_b if surveyed_p2_r1_b==1

			* Endline
			sum g10c_e g10d_e g10e_e g10f_e if p1_e5m==1
			sum g10c_e g10d_e g10e_e g10f_e if p1_e12m==1
			sum g10c_e g10d_e g10e_e g10f_e if p1_e13m==1
			sum g10c_e g10d_e g10e_e g10f_e if p3_e2w==1
			sum g10c_e g10d_e g10e_e g10f_e if p3_e5w==1
			sum g10cv2_e g10dv2_e g10ev2_e g10fv2_e if p1_e7m==1
			sum g10cv2_e g10dv2_e g10ev2_e g10fv2_e if p2_e2w2w==1

		* Rename the first version v1 (This should be in the individual dofiles)
			ren g10c_b g10cv1_b
			ren g10d_b g10dv1_b
			ren g10e_b g10ev1_b
			ren g10f_b g10fv1_b

			ren g10c_e g10cv1_e
			ren g10d_e g10dv1_e
			ren g10e_e g10ev1_e
			ren g10f_e g10fv1_e

		* Generate a combined version
			gen g10c_b = g10cv1_b
			gen g10d_b = g10dv1_b
			gen g10e_b = g10ev1_b
			gen g10f_b = g10fv1_b

			gen g10c_e = g10cv1_e if p1_e5m==1 | p1_e12m ==1 | p1_e13m ==1 | p3_e2w==1 | p3_e5w==1 | p2_e12m==1 | p2_e13m==1 | p3_e12m==1 | p3_e13m==1 | p1_e9y==1 | p2_e9y==1 | p3_e9y==1 |p1_e10y==1 |p2_e10y==1 |p3_e10y==1
			replace g10c_e = g10cv2_e if p1_e7m==1 | p2_e2w2w ==1
			gen g10d_e = g10dv1_e if p1_e5m==1 | p1_e12m ==1 | p1_e13m ==1 | p3_e2w==1 | p3_e5w==1| p2_e12m==1 | p2_e13m==1 | p3_e12m==1 | p3_e13m==1 | p1_e9y==1 | p2_e9y==1 | p3_e9y==1 |p1_e10y==1 |p2_e10y==1 |p3_e10y==1
			replace g10d_e = g10dv2_e if p1_e7m==1 | p2_e2w2w ==1
			gen g10e_e = g10ev1_e if p1_e5m==1 | p1_e12m ==1 | p1_e13m ==1 | p3_e2w==1 | p3_e5w==1| p2_e12m==1 | p2_e13m==1 | p3_e12m==1 | p3_e13m==1 | p1_e9y==1 | p2_e9y==1 | p3_e9y==1 |p1_e10y==1 |p2_e10y==1 |p3_e10y==1
			replace g10e_e = g10ev2_e if p1_e7m==1 | p2_e2w2w ==1
			gen g10f_e = g10fv1_e if p1_e5m==1 | p1_e12m ==1 | p1_e13m ==1 | p3_e2w==1 | p3_e5w==1| p2_e12m==1 | p2_e13m==1 | p3_e12m==1 | p3_e13m==1 | p1_e9y==1 | p2_e9y==1 | p3_e9y==1 |p1_e10y==1 |p2_e10y==1 |p3_e10y==1
			replace g10f_e = g10fv2_e if p1_e7m==1 | p2_e2w2w ==1

		* Generate indices
			foreach p in b e {
				gen risk_game_real_`p' = 1 if g10c_`p'==2 & g10e_`p' ==2
				replace risk_game_real_`p' = 2 if g10c_`p'==2 & g10e_`p' ==1
				replace risk_game_real_`p' = 3 if g10c_`p'==1 & g10d_`p' ==2
				replace risk_game_real_`p' = 4 if g10c_`p'==1 & g10d_`p' ==1
					la var risk_game_real_`p' "Risk total index ADD RISK AVERSE (Real money game) (1-4)"

				gen risk_game_resc_`p' = risk_game_real_`p' - 1
					la var risk_game_resc_`p' "Risk total index ADD RISK AVERSE (0-3)"

				gen lossaversion_game_real_`p' = (g10f_`p'==1) if g10f_`p'!=.
					la var lossaversion_game_real_`p' "Loss Aversion"

				gen riskaversion_game_real_`p' = risk_game_real_`p' + lossaversion_game_real_`p'
					la var riskaversion_game_real_`p' "Risk Aversion Index"
			/* Generate rescaled components */
				foreach x in g10c  g10d  g10e {
					qui gen `x'_resc_`p' = 2 - `x'_`p'
						la var `x'_resc_`p' "`x' rescaled, 1: more risk averse"
				}
			}

	// Risk declared ADD RISK AVERSE (July 2014)

			* Was 200=1; 75=2 (higher=less risky); we change 75=0 (higher=more risky)
				foreach var in risk_decl_keepjob200vs75_b risk_decl_keepjob250vs50_b   {
					gen `var'_resc= `var'
					replace `var'_resc=0 if `var'_resc==2
						la var `var'_resc "Rescaled: `var' higher=more risky"
				}

				foreach var in risk_decl_keepjob200vs75_e risk_decl_keepjob250vs50_e  {
					gen `var'_resc= `var'
					replace `var'_resc=0 if `var'_resc==2
						la var `var'_resc "Rescaled: `var' higher=more risky"
				}

					rename risk_decl_keepjob200vs75_b_resc risk_decl_keepjob200vs75_resc_b
					rename risk_decl_keepjob200vs75_e_resc risk_decl_keepjob200vs75_resc_e
					rename risk_decl_keepjob250vs50_b_resc risk_decl_keepjob250vs50_resc_b
					rename risk_decl_keepjob250vs50_e_resc risk_decl_keepjob250vs50_resc_e

					label define keepjobs 1 "200 USD" 0 "75 USD"
					label values risk_decl_keepjob200vs75_resc_b risk_decl_keepjob200vs75_resc_e risk_decl_keepjob250vs50_resc_b risk_decl_keepjob250vs50_resc_e keepjobs

			* Rescale risk_decl_plentyprofit* so that higher=more risky
				foreach var in risk_decl_plentyprofit_b risk_decl_plentyprofit_e {
					gen `var'_resc= `var'
					replace `var'_resc=0 if `var'_resc==2
						la var `var'_resc "Rescaled: `var' higher=more risky"
				}

				rename risk_decl_plentyprofit_b_resc risk_decl_plentyprofit_resc_b
				rename risk_decl_plentyprofit_e_resc risk_decl_plentyprofit_resc_e

				label define plentyprofits 1 "plenty profit" 0 "Low profit"
				label values risk_decl_plentyprofit_resc_b risk_decl_plentyprofit_resc_e plentyprofits


			* Rescale risk_decl_gamble* so that higher=more risky
				foreach var in risk_decl_gamble_b risk_decl_gamble_e {
					gen `var'_resc= `var'
					recode `var'_resc (4=0) (3=1) (2=2) (1=3)
						la var `var'_resc "Rescaled: `var' higher=more risky"
				}

				rename risk_decl_gamble_b_resc risk_decl_gamble_resc_b
				rename risk_decl_gamble_e_resc risk_decl_gamble_resc_e

				label define games 0 "no" 1 "one one time" 2 "sometimes" 3 "everytime"
				label values risk_decl_gamble_resc_b risk_decl_gamble_resc_e games


	*Create one KeepJob variable*

		generate risk_decl_keepjob_b=1 if risk_decl_keepjob200vs75_resc_b==0 & risk_decl_keepjob250vs50_resc_b==0
		replace risk_decl_keepjob_b=2 if (risk_decl_keepjob200vs75_resc_b==0 & risk_decl_keepjob250vs50_resc_b==1) | (risk_decl_keepjob200vs75_resc_b==1 & risk_decl_keepjob250vs50_resc_b==0)
		replace risk_decl_keepjob_b=3 if risk_decl_keepjob200vs75_resc_b==1 & risk_decl_keepjob250vs50_resc_b==1

		generate risk_decl_keepjob_e=1 if risk_decl_keepjob200vs75_resc_e==0 & risk_decl_keepjob250vs50_resc_e==0
		replace risk_decl_keepjob_e=2 if (risk_decl_keepjob200vs75_resc_e==0 & risk_decl_keepjob250vs50_resc_e==1) | (risk_decl_keepjob200vs75_resc_e==1 & risk_decl_keepjob250vs50_resc_e==0)
		replace risk_decl_keepjob_e=3 if risk_decl_keepjob200vs75_resc_e==1 & risk_decl_keepjob250vs50_resc_e==1

		label var risk_decl_keepjob_b "Keep Job (RiskTime: tr21,22)"
		label var risk_decl_keepjob_e "Keep Job (RiskTime: tr21, 20)"


** TIME PREFERENCES **

	ren g9e_b g9ev1_b
	ren g9f_b g9fv1_b
	ren g9g_b g9gv1_b
	ren g9h_b g9hv1_b
	ren g9i_b g9iv1_b
	ren g9j_b g9jv1_b

	ren g9e_e g9ev1_e
	ren g9f_e g9fv1_e
	ren g9g_e g9gv1_e
	ren g9h_e g9hv1_e
	ren g9i_e g9iv1_e
	ren g9j_e g9jv1_e

	gen g9e_b = g9ev1_b if p1==1 | p2 ==1 | p3 ==1
	gen g9f_b = g9fv1_b if p1==1 | p2 ==1 | p3 ==1
	gen g9g_b = g9gv1_b if p1==1 | p2 ==1 | p3 ==1
	gen g9h_b = g9hv1_b if p1==1 | p2 ==1 | p3 ==1
	gen g9i_b = g9iv1_b if p1==1 | p2 ==1 | p3 ==1
	gen g9j_b = g9jv1_b if p1==1 | p2 ==1 | p3 ==1

	gen g9e_e = g9ev1_e if p1_e3wks==1 | p1_e12m ==1 | p1_e13m ==1 | p3_e2w==1 | p3_e5w==1 | p2_e12m==1 | p2_e13m==1 | p3_e12m==1 | p3_e13m==1 | p1_e9y==1 | p2_e9y==1 | p3_e9y==1 |p1_e10y==1 |p2_e10y==1 |p3_e10y==1
	replace g9e_e = g9ev2_e if p1_e5m ==1 | p2_e2wks ==1 | p1_e9y==1 | p2_e9y==1 | p3_e9y ==1
	replace g9e_e = g9ev3_e if p1_e7m ==1 | p2_e2w2w ==1 | p1_e10y==1 | p2_e10y==1 | p3_e10y ==1

	gen g9f_e = g9fv1_e if p1_e3wks==1 | p1_e12m ==1 | p1_e13m ==1 | p3_e2w==1 | p3_e5w==1 | p2_e12m==1 | p2_e13m==1 | p3_e12m==1 | p3_e13m==1 | p1_e9y==1 | p2_e9y==1 | p3_e9y==1 |p1_e10y==1 |p2_e10y==1 |p3_e10y==1
	replace g9f_e = g9fv2_e if p1_e5m ==1 | p2_e2wks ==1 | p1_e9y==1 | p2_e9y==1 | p3_e9y ==1
	replace g9f_e = g9fv3_e if p1_e7m ==1 | p2_e2w2w ==1 | p1_e10y==1 | p2_e10y==1 | p3_e10y ==1

	gen g9g_e = g9gv1_e if p1_e3wks==1 | p1_e12m ==1 | p1_e13m ==1 | p3_e2w==1 | p3_e5w==1 | p2_e12m==1 | p2_e13m==1 | p3_e12m==1 | p3_e13m==1 | p1_e9y==1 | p2_e9y==1 | p3_e9y==1 |p1_e10y==1 |p2_e10y==1 |p3_e10y==1
	replace g9g_e = g9gv2_e if p1_e5m ==1 | p2_e2wks ==1 | p1_e9y==1 | p2_e9y==1 | p3_e9y ==1
	replace g9g_e = g9gv3_e if p1_e7m ==1 | p2_e2w2w ==1 | p1_e10y==1 | p2_e10y==1 | p3_e10y ==1

	gen g9h_e = g9hv1_e if p1_e3wks==1 | p1_e12m ==1 | p1_e13m ==1 | p3_e2w==1 | p3_e5w==1 | p2_e12m==1 | p2_e13m==1 | p3_e12m==1 | p3_e13m==1 | p1_e9y==1 | p2_e9y==1 | p3_e9y==1 |p1_e10y==1 |p2_e10y==1 |p3_e10y==1
	replace g9h_e = g9hv2_e if p1_e5m ==1 | p2_e2wks ==1 | p1_e9y==1 | p2_e9y==1 | p3_e9y ==1
	replace g9h_e = g9hv3_e if p1_e7m ==1 | p2_e2w2w ==1 | p1_e10y==1 | p2_e10y==1 | p3_e10y ==1

	gen g9i_e = g9iv1_e if p1_e3wks==1 | p1_e12m ==1 | p1_e13m ==1 | p3_e2w==1 | p3_e5w==1 | p2_e12m==1 | p2_e13m==1 | p3_e12m==1 | p3_e13m==1 | p1_e9y==1 | p2_e9y==1 | p3_e9y==1 |p1_e10y==1 |p2_e10y==1 |p3_e10y==1
	replace g9i_e = g9iv2_e if p1_e5m ==1 | p2_e2wks ==1 | p1_e9y==1 | p2_e9y==1 | p3_e9y ==1
	replace g9i_e = g9iv3_e if p1_e7m ==1 | p2_e2w2w ==1 | p1_e10y==1 | p2_e10y==1 | p3_e10y ==1

	gen g9j_e = g9jv1_e if p1_e3wks==1 | p1_e12m ==1 | p1_e13m ==1 | p3_e2w==1 | p3_e5w==1 | p2_e12m==1 | p2_e13m==1 | p3_e12m==1 | p3_e13m==1 | p1_e9y==1 | p2_e9y==1 | p3_e9y==1 |p1_e10y==1 |p2_e10y==1 |p3_e10y==1
	replace g9j_e = g9jv2_e if p1_e5m ==1 | p2_e2wks ==1 | p1_e9y==1 | p2_e9y==1 | p3_e9y ==1
	replace g9j_e = g9jv3_e if p1_e7m ==1 | p2_e2w2w ==1 | p1_e10y==1 | p2_e10y==1 | p3_e10y ==1

	foreach p in b e {

		// Patience and time inconsistency - Real money game trade-offs, in IBMs

			* Variables for p1_e3wks and p2_e2wks
				sum g9e_`p' g9g_`p' g9h_`p' g9f_`p' g9i_`p' g9j_`p'

			* Sub Index : Patience Score

				gen patient0_real_`p'=.
				gen patient1_real_`p'=.

				* Now versus two weeks
					replace patient0_real_`p'=0 if g9e_`p'==1 & g9g_`p'==1
					replace patient0_real_`p'=1 if g9e_`p'==1 & g9g_`p'==2
					replace patient0_real_`p'=2 if g9e_`p'==2 & g9h_`p'==1
					replace patient0_real_`p'=3 if g9e_`p'==2 & g9h_`p'==2
						la var patient0_real_`p' "Patience Score Now (Real money game) (0-3)"

				* Two weeks versus four weeks
					replace patient1_real_`p'=0 if g9f_`p'==1 & g9i_`p'==1
					replace patient1_real_`p'=1 if g9f_`p'==1 & g9i_`p'==2
					replace patient1_real_`p'=2 if g9f_`p'==2 & g9j_`p'==1
					replace patient1_real_`p'=3 if g9f_`p'==2 & g9j_`p'==2
						la var patient1_real_`p' "Patience Score 2 weeks (Real money game) (0-3)"

			* Index

				gen patient_game_real_`p' = patient0_real_`p' + patient1_real_`p'
					la var patient_game_real_`p' "Patience total index (IBM) (0-6)"

				gen incon_game_real_`p' = patient1_real_`p' - patient0_real_`p'
					la var incon_game_real_`p' "Time inconsistency index (IBM) (-3 to 3) higher==lack of impulse control"

				gen incon_game_resc_`p' = incon_game_real_`p' + 3
					la var incon_game_resc_`p' "Time inconsistency index (IBM) (0 to 6)"

				gen incon_game_real_dum_`p' = (incon_game_real_`p'>0) if incon_game_real_`p'!=.
					la var incon_game_real_dum_`p' "Time inconsistency indicator (IBM) 1 if lack of impulse control"

				bysort phase round: summ patient0_real_`p' patient1_real_`p' patient_game_real_`p' incon_game_real_`p' incon_game_real_dum_`p'

		}


		egen patience_rstd_b = std(patient_game_real_b)
        label variable patience_rstd_b         "Index of patience, z-score"



		foreach p in b e {

	// Patience and time inconsistency - Declared/Hypothetical money game trade-offs, in survey

		* Variables for p1_e5m and p1_e3wks
			summ time_hyp_mnygm1_`p' time_hyp_mnygm2_`p' time_hyp_mnygm3_`p' time_hyp_mnygm4_`p' time_hyp_mnygm5_`p' time_hyp_mnygm6_`p'
			destring time_hyp_mnygm1_`p' time_hyp_mnygm3_`p' time_hyp_mnygm4_`p' time_hyp_mnygm5_`p', force replace
			* Sub Index : Patience Score

				gen patient0_decl_`p'=.
				gen patient1_decl_`p'=.

				* Now versus two weeks
					replace patient0_decl_`p'=0 if time_hyp_mnygm1_`p'==1 & time_hyp_mnygm3_`p'==1
					replace patient0_decl_`p'=1 if time_hyp_mnygm1_`p'==1 & time_hyp_mnygm3_`p'==2
					replace patient0_decl_`p'=2 if time_hyp_mnygm1_`p'==2 & time_hyp_mnygm4_`p'==1
					replace patient0_decl_`p'=3 if time_hyp_mnygm1_`p'==2 & time_hyp_mnygm4_`p'==2
						la var patient0_decl_`p' "Patience score now (Declared money game) (0-3)"

				* Two weeks versus four weeks
					replace patient1_decl_`p'=0 if time_hyp_mnygm2_`p'==1 & time_hyp_mnygm5_`p'==1
					replace patient1_decl_`p'=1 if time_hyp_mnygm2_`p'==1 & time_hyp_mnygm5_`p'==2
					replace patient1_decl_`p'=2 if time_hyp_mnygm2_`p'==2 & time_hyp_mnygm6_`p'==1
					replace patient1_decl_`p'=3 if time_hyp_mnygm2_`p'==2 & time_hyp_mnygm6_`p'==2
						la var patient1_decl_`p' "Patience score 2wks (Declared money game) (0-3)"

			* Index

				gen patient_game_decl_`p' = patient0_decl_`p' + patient1_decl_`p'
					la var patient_game_decl_`p' "Patience total index (Declared money game) (0 6)"
					qui sum patient_game_decl_`p'
					qui gen patient_game_declstd_`p' = (patient_game_decl_`p'-r(mean))/r(sd)

				gen incon_game_decl_`p' = patient1_decl_`p' - patient0_decl_`p'
					la var incon_game_decl_`p' "Time inconsistency index (Declared money game) (-3 to 3)"
					qui sum incon_game_decl_`p'
					qui gen incon_game_declstd_`p' = (incon_game_decl_`p'-r(mean))/r(sd)

				gen incon_game_decl_dum_`p' = (incon_game_decl_`p'>0 & incon_game_decl_`p'!=.) if incon_game_decl_`p'!=.
					la var incon_game_decl_dum_`p' "Time inconsistency indicator (Declared money game)"


				bysort phase round: summ patient0_decl_`p' patient1_decl_`p' patient_game_decl_`p' incon_game_decl_`p' incon_game_decl_dum_`p'

		}


	// Declared patience measures

		foreach p in b e {

		* Variables
			sum time_decl_waitexam2dys_`p' time_decl_waitexam1dys_`p' time_decl_waitexam3dys_`p' time_decl_waitexam1w_`p' time_decl_patient_`p' time_decl_saveproblems_`p' time_decl_hidemoney_`p' time_decl_umbrellas_`p' time_decl_medicine_`p' time_decl_celebrate_`p' time_decl_regretspend_`p'
			codebook time_decl_waitexam2dys_`p' time_decl_waitexam1dys_`p' time_decl_waitexam3dys_`p' time_decl_waitexam1w_`p' time_decl_patient_`p' time_decl_saveproblems_`p' time_decl_hidemoney_`p' time_decl_umbrellas_`p' time_decl_medicine_`p' time_decl_celebrate_`p' time_decl_regretspend_`p'

		* Wiating for a medical exam
			gen time_decl_waitexam_`p'=0
			replace time_decl_waitexam_`p'=1 if time_decl_waitexam1dys_`p'==1
			replace time_decl_waitexam_`p'=2 if time_decl_waitexam2dys_`p'==1
			replace time_decl_waitexam_`p'=3 if time_decl_waitexam3dys_`p'==1
			replace time_decl_waitexam_`p'=7 if time_decl_waitexam1w_`p'==1
			replace time_decl_waitexam_`p'=. if time_decl_waitexam1dys_`p'==. & time_decl_waitexam2dys_`p'==.
				la var time_decl_waitexam_`p' "How many days would you wait for a free medical exam?"

		* Positive questions: Change to 0-No 1-One one time 2-Sometimes 3-Everytime
			foreach var in patient saveproblems hidemoney  {
				gen time_decl_`var'_resc_`p' = time_decl_`var'_`p'*-1+4
				la var time_decl_`var'_resc_`p' "Rescaled: `var'"
			}
		* Positive questions: Change to 0-No 1-One one time 2-Sometimes 3-Everytime
			foreach var in avdmnywstingfrnds avdthvngfrnds  {
				gen th_`var'_resc_`p' = time_hyp_`var'_`p'*-1+4
				la var th_`var'_resc_`p' "Rescaled: `var'"
			}

		* Change to 0-not patient 1-patient instead of 1 and 2
			foreach var in time_decl_umbrellas time_decl_medicine {
				gen `var'_resc_`p' = `var'_`p'-1
				la var `var'_resc_`p' "Rescaled: `var'"
			}

		* Negative question : Change to 0-Everytime 1-Sometimes 2-One one time 3-No
			foreach var in time_decl_celebrate time_decl_regretspend {
				gen `var'_resc_`p' = `var'_`p'-1
				la var `var'_resc_`p' "Rescaled: `var'"
			}

		* No change
			* time_decl_patiencelad

		* Analyze responses
			gl time "time_decl_waitexam_`p' time_decl_patient_resc_`p' time_decl_saveproblems_resc_`p' time_decl_umbrellas_resc_`p' time_decl_medicine_resc_`p' time_decl_celebrate_resc_`p' time_decl_patienceladder_`p' time_decl_hidemoney_resc_`p' time_decl_regretspend_resc_`p'"
			summ $time, d
			pwcorr $time, star (.05)
			factor $time
				rotate


	 }




	// FUNNY BUSINESS WITH THE PHASE 2 TP LUCKY TICKET

		* CASH GRANT  General Impression about Tricherie  -- Whole Sample
			sum lottogrntanysmallhelp_e  lottogrntinfl_e lottogrntcrrptn_e lottogrntfair_e if p2_e2w2w

		* TP General Impression about Tricherie -- Whole Sample
			sum lottotpanysmallhelp_e  lottotpcrrptn_e  lottotpfair_e lottotpinfl_e

			ta lottotpanysmallhelpnum_e if  lottotpanysmallhelp_e==1 & p2_e2w2w==1
			ta lottotpcrrptnhow_e if  lottotpcrrptn_e==1 & p2_e2w2w==1
			ta lottotpinflhow_e if  lottotpinfl_e==1 & p2_e2w2w==1

		* TP Respondent got some kind of help in drawing the ticket  -- Whole Sample (324)

			* Respondent drew unlucky ticket and then could draw again: lottotpselectdrawagain lottotpnoselectdrawagain
				gen lottotpdrawagain_e =  lottotpselectdrawagain_e  if p2_e2w2w==1 & lottotpselect_e ==1
				replace lottotpdrawagain_e =  lottotpnoselectdrawagain_e  if p2_e2w2w==1 & lottotpselect_e ==0
					la var lottotpdrawagain_e "Respondent could draw again"

			* Respondent could see inside the jar : lottotpselectseesmall lottotpnoselectseesmall
				gen lottotpseesmall_e =  lottotpselectseesmall_e  if p2_e2w2w==1 & lottotpselect_e ==1
				replace lottotpseesmall_e =  lottotpnoselectseesmall_e  if p2_e2w2w==1 & lottotpselect_e ==0
					la var lottotpseesmall_e "Respondent could see small inside the jar"


			* Respondent could other kind of help : lottotpselectothhelp lottotpnoselectothhelp
				gen lottotpothhelp_e =  lottotpselectothhelp_e  if p2_e2w2w==1 & lottotpselect_e ==1
				replace lottotpothhelp_e =  lottotpnoselectothhelp_e  if p2_e2w2w==1 & lottotpselect_e ==0
					la var lottotpothhelp_e "Respondent got other small help"

			sum lottotpothhelp_e lottotpselectothhelp_e lottotpnoselectothhelp_e if p2_e2w2w
			sum lottotpseesmall_e lottotpselectseesmall_e lottotpnoselectseesmall_e if p2_e2w2w
			sum lottotpdrawagain_e  lottotpselectdrawagain_e  lottotpnoselectdrawagain_e if p2_e2w2w


			tab1 lottotpselectothhelphow_e lottotpnoselectothhelphow_e if lottotpothhelp_e==1

		* TP Respondent Lost Lucky tix but got into the tp -- Only Selected People

			* Respondent feels that it could influence the assistant : lottotpselectinfl
			sum lottotpselectinfl_e if p2_e2w2w ==1 & lottotpselect_e ==1

			* Respondent drew unlucky ticket but was selected : lottotpselectwithoutwin
			sum lottotpselectwithoutwin_e if p2_e2w2w ==1 & lottotpselect_e ==1

			* Respondent drew unlucky ticket but got his ticket switched : lottotpselectswitch
			sum lottotpselectswitch_e if p2_e2w2w ==1 & lottotpselect_e ==1

		* TP Respondent Won the lucky tix but didnt got in the tp-- Only Not Selected People

			* Respondent was prevented from winning :
			sum lottotpnoselectpreventwin_e if p2_e2w2w==1 & lottotpselect_e ==0

			* Respondent drew the lucky ticket but was not selected for the tp : lottotpnoselectwithwin
			sum lottotpnoselectwithwin_e if p2_e2w2w==1 & lottotpselect_e ==0




			/* Construct risk */
		*********************
			/* Baseline */
			/* Impute and standardize components */
			foreach x in time_decl_spendquick th_avdmnywstingfrnds_resc th_avdthvngfrnds_resc time_decl_celebrate time_decl_saveproblems_resc time_decl_patienceladder time_decl_patient_resc {
				qui sum `x'_b if round == 1, d
				qui gen `x'm_b = cond(!missing(`x'_b),`x'_b,r(p50))
				qui sum `x'm_b if round == 1
				qui gen `x'z_b = (`x'm_b - r(mean))/r(sd)
				la var `x'z_b "`: var la `x'_b' (standardized, imputed)"
			}
			qui egen timedecl_b = rowtotal (time_decl_spendquickz_b th_avdmnywstingfrnds_rescz_b th_avdthvngfrnds_rescz_b time_decl_celebratez_b time_decl_saveproblems_rescz_b time_decl_patienceladderz_b time_decl_patient_rescz_b)
			qui sum timedecl_b if round == 1
			qui replace timedecl_b = (timedecl_b-r(mean))/r(sd)
				la var timedecl_b "Declared patience (higher = more patient)"


			/* Endline */
			foreach x in time_decl_spendquick th_avdmnywstingfrnds_resc th_avdthvngfrnds_resc time_decl_celebrate time_decl_saveproblems_resc time_decl_patienceladder time_decl_patient_resc {
				qui sum `x'_e if round == 1, d
				qui gen `x'm_e = cond(!missing(`x'_e),`x'_e,r(p50))
				qui sum `x'm_e if round == 1
				qui gen `x'z_e = (`x'm_e - r(mean))/r(sd)
				la var `x'z_e "`: var la `x'_e' (standardized, imputed)"
			}
			qui egen timedecl_e = rowtotal (time_decl_spendquickz_e th_avdmnywstingfrnds_rescz_e th_avdthvngfrnds_rescz_e time_decl_celebratez_e time_decl_saveproblems_rescz_e time_decl_patienceladderz_e time_decl_patient_rescz_e)
			qui sum timedecl_e if round == 1
			qui replace timedecl_e = (timedecl_e-r(mean))/r(sd)
				la var timedecl_e "Declared patience (higher = more patient)"

			/* Individual components */
			qui egen timedecl_p_e = rowtotal (time_decl_saveproblems_rescz_e time_decl_patienceladderz_e time_decl_patient_rescz_e)
			qui sum timedecl_p_e if round == 1
			qui replace timedecl_p_e = (timedecl_p_e-r(mean))/r(sd)
				la var timedecl_p_e "Declared patience (higher = more patient)"

			qui egen timedecl_t_e = rowtotal (time_decl_spendquickz_e th_avdmnywstingfrnds_rescz_e time_decl_celebratez_e)
			qui sum timedecl_t_e if round == 1
			qui replace timedecl_t_e = (timedecl_t_e-r(mean))/r(sd)
				la var timedecl_t_e "Declared time inconsistency (higher = more time consistent)"


		/* Construct time preference */
		********************
			foreach x in riskladder keepjob gamble_resc  plentyprofit_resc dangerfun motorcyclenight {
				qui sum risk_decl_`x'_b if round == 1, d
				qui gen rd_`x'med_b = cond(!missing(risk_decl_`x'_b),risk_decl_`x'_b,r(p50))
				qui sum rd_`x'med_b if round == 1
				qui gen rd_`x'_std_b = (rd_`x'med_b - r(mean))/r(sd)
				la var rd_`x'_std_b "`: var la risk_decl_`x'_b' (standardized, imputed)"
			}
			qui egen riskdecl_b = rowtotal(rd_riskladder_std_b rd_keepjob_std_b rd_gamble_resc_std_b  rd_plentyprofit_resc_std_b rd_dangerfun_std_b rd_motorcyclenight_std_b)
			qui sum riskdecl_b if round == 1
			qui replace riskdecl_b = (riskdecl_b-r(mean))/r(sd)
			la var riskdecl_b "Declared risk appetite (higher = less risk aversion)"





	* Clean Game 2 Code *
gen threshold = 1000 if inlist(round,1,5)
replace threshold = 500 if inlist(round,2,6)
replace threshold = 1500 if inlist(round,7)

foreach var in  g11a g11b g11c g11d g11e g11f g11g g11h g11i g11j g11k ///
				g12a g12b g12c g12d g12e g12f g12g g12h g12i g12j g12k {
	gen `var'_s_e = substr(`var'_e,3,4)
	replace `var'_s_e = "" if `var'_s_e == "-Mis"
	destring `var'_s_e, replace
	*arbitrary for missing values*
	replace `var'_s_e = 10000 if `var'_s_e == threshold & `var'_s_e != .
	}

egen min_now = rowmin(g11a_s_e g11b_s_e g11c_s_e g11d_s_e g11e_s_e g11f_s_e g11g_s_e g11h_s_e g11i_s_e g11j_s_e g11k_s_e)
	gen d_rate_now_e = min_now/threshold
	*top code at 4
	replace d_rate_now_e = 4 if d_rate_now_e > 4 & d_rate_now_e < .
	drop min_now

egen min_fut = rowmin(g12a_s_e g12b_s_e g12c_s_e g12d_s_e g12e_s_e g12f_s_e g12g_s_e g12h_s_e g12i_s_e g12j_s_e g12k_s_e)
	gen d_rate_fut_e = min_fut/threshold
	*top code at 4
	replace d_rate_fut_e = 4 if d_rate_fut_e > 4 & d_rate_fut_e < .
	drop min_fut

drop *_s_e

foreach time in now fut {
	gen patient_rate_`time'_e = -d_rate_`time'_e + 4 if -d_rate_`time'_e != .
	label var patient_rate_`time'_e "Patience rate from discount rate, `time'"
	}

	gen d_rate_e = .5 * (d_rate_now_e + d_rate_fut_e)
	lab var d_rate_e "Average discount rate, .9 to 4)"

	gen patient_rate_dsct_e = (patient_rate_now_e + patient_rate_fut_e)/2
	lab var patient_rate_dsct_e "Average patience rate from discount rates, (0-3.1)"

	gen incon_rate_dsct_e = d_rate_fut_e - d_rate_now_e
	lab var incon_rate_dsct_e "Inconsistent rate from discount rates (-3.1 to 3.1)"

	gen incon_dum_dsct_e = 1 if incon_rate_dsct_e > 0 & incon_rate_dsct_e != .
		replace incon_dum_dsct_e = 0 if incon_rate_dsct_e <= 0
		lab var incon_dum_dsct_e "Inconsistent indicator from discount rates"
